﻿using System;
using UnityEngine;

namespace Assets.Scripts.DynamicClouds
{
	// Token: 0x0200028F RID: 655
	public class CloudShadowDetector : MonoBehaviour
	{
		// Token: 0x06000E86 RID: 3718 RVA: 0x000702CB File Offset: 0x0006E4CB
		private void Start()
		{
			base.transform.eulerAngles = SimpleSunController.SunDirection;
		}

		// Token: 0x06000E87 RID: 3719 RVA: 0x000702E0 File Offset: 0x0006E4E0
		public void ShadowCheck()
		{
			base.transform.eulerAngles = SimpleSunController.SunDirection;
			Ray ray = new Ray(base.transform.position, -base.transform.forward);
			RaycastHit[] array = Physics.RaycastAll(ray, (float)this.GetShadowsFrom);
			int num = array.Length + 1;
			int num2 = 0;
			if (!this.GtsCastsOnlyLiteShadow)
			{
				bool flag = false;
				foreach (RaycastHit raycastHit in array)
				{
					if (raycastHit.collider.gameObject.layer == Layers.gtsBodyLayer)
					{
						flag = true;
					}
					if (raycastHit.collider.gameObject.layer == Layers.cloudProximityLayer)
					{
						num2++;
					}
				}
				if (flag)
				{
					num += this.GtsShadowFactor;
				}
				num -= num2;
			}
			num *= 2;
			this.ShadeAmount = Mathf.Clamp(num, 1, this.Shades.Length - 1);
			if (this.mPreviousShade != this.ShadeAmount)
			{
				this.Clouds.colorOverLifetime.color = this.Shades[this.ShadeAmount];
				this.mPreviousShade = this.ShadeAmount;
			}
		}

		// Token: 0x040013A1 RID: 5025
		public bool GtsCastsOnlyLiteShadow;

		// Token: 0x040013A2 RID: 5026
		public int GtsShadowFactor = 100;

		// Token: 0x040013A3 RID: 5027
		public ParticleSystem Clouds;

		// Token: 0x040013A4 RID: 5028
		public Gradient[] Shades;

		// Token: 0x040013A5 RID: 5029
		private Gradient mOrignalColor;

		// Token: 0x040013A6 RID: 5030
		public int ShadeAmount;

		// Token: 0x040013A7 RID: 5031
		private int mPreviousShade;

		// Token: 0x040013A8 RID: 5032
		public LayerMask GetShadowsFrom;
	}
}
